<template>
  <div>
    <el-dialog @close="change" v-model="dialogState" title="编辑员工信息">
      <el-form :inline="true" :model="row">
        <el-form-item label="* 编号" :label-width="formLabelWidth">
          <el-input v-model="row.workerId" autocomplete="off"/>
        </el-form-item>
        <el-form-item label="* 姓名" :label-width="formLabelWidth">
          <el-input v-model="row.name" disabled/>
        </el-form-item>
        <el-form-item label="* 状态" :label-width="formLabelWidth">
        <el-input v-model="row.status" disabled/>
        </el-form-item>
        <el-form-item label="* 调动部门" :label-width="dropLabelWidth">
          <el-select v-model="row.curDept" placeholder="请选择部门">
            <el-option v-for="item in depts" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="* 现岗位" :label-width="formLabelWidth">
          <el-input v-model="row.formerPost" disabled/>
        </el-form-item>
        <el-form-item label="* 调动岗位" :label-width="dropLabelWidth">
          <el-input v-model="row.curPost" autocomplete="off"/>
        </el-form-item>
        <el-form-item label="* 现部门" :label-width="formLabelWidth">
        <el-input v-model="row.formerDept" disabled></el-input>
        </el-form-item>
        <el-form-item label="* 变动时间" :label-width="formLabelWidth">
          <div class="block">
            <el-date-picker v-model="row.transferDate"
                            type="date"
                            value-format="YYYY-MM-DD"
                            placeholder="选择变动日期">
            </el-date-picker>
          </div>
        </el-form-item>
      </el-form>
      <!-- 表单尾部取消和确认按钮 -->
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="change">取消</el-button>
        <el-button type="primary" @click="confirm">确认</el-button>
      </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import {debounce} from "../../../plugins/utils";
  export default {
    name: "MyDialog",
    props: {
      row: {
        type: Object,
        default() {
          return {
            name: "",
            workerId: "",
            formerDept: "",
            formerPost: "",
            curDept: "",
            curPost: "",
            transferDate: ""
          }
        }
      },
      depts: {
        type: Array,
        default() {
          return []
        }
      },
      dialogState: {
        type: Boolean,
        default() {
          return true;
        }
      },
      formLabelWidth: {
        type: String,
        default() {
          return "90px";
        }
      },
      dropLabelWidth: {
        type: String,
        default() {
          return "90px";
        }
      }
    },
    data() {
      return {
        debounce_get: ""
      }
    },
    methods: {
      confirm() {
        this.$bus.emit('confirmOperation', this.row)
      },
      change() {
        this.$bus.emit('changeDialogState')
      },
      async getCurrentEmployeeInfos(workerId) {
        let result = await this.$request('/transfer/currentinfo', {
          workerId
        });
        const info = result.data[0];
        console.log(result.data[0]);
        this.row.name = info.name;
        this.row.status = info.status;
        this.row.formerDept = info.dept;
        this.row.formerPost = info.post;
      }
    },
    watch: {
      'row.workerId'(newv, oldv) {
        this.debounce_get(newv);
      }
    },
    created() {
      this.debounce_get = debounce(this.getCurrentEmployeeInfos, 1500);
    }
  }
</script>

<style scoped>

</style>